<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">距离十一放假还有：xx天xx时xx分xx秒</div>
</body>
<script>
    var box = document.getElementsByClassName("box")[0];//获取元素
    var date = "2021-10-1"; //设置倒计时的日期
    timeCount(date); //网页加载时先调用函数打印一遍倒计时
    var timer = setInterval(timeCount, 1000, date); //设置计时器开始计时，一秒钟一次

    function timeCount(date) { //设置
        var now = new Date(); //获取当前日期
        var future = new Date(date); //获取需要倒计时的时间
        var ms = future - now;
        var time = parseInt(ms / 1000);

        if (future > now) { //time>0
            var day = parseInt(time / (60 * 60 * 24));
            var hour = parseInt(time / (60 * 60) % 24);// time / 一小时的时间  => 小时的倍数
            var minute = parseInt(time / 60 % 60);// time / 一分钟的时间  => 分钟的倍数
            var second = time % 60;
            box.innerText = `距离十一放假还有：${day}天${beauty(hour)}时${beauty(minute)}分${beauty(second)}秒`;
        } else {
            clearInterval(timer); // 清除计时器
            box.innerText = '倒计时结束！'
        }
    }

    function beauty(num) {
        return num < 10 ? "0" + num : num;
    }
</script>

</html>